package com.waiting.annotation;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import javax.tools.Diagnostic;
import java.util.Set;

/**
 * @Description @Adapt注解的注解处理器
 * @Author bjweitingting
 * @Date 2019/1/14
 **/
public class AdaptProcessor extends AbstractProcessor {

    /**
     * 注解处理的具体过程
     *
     * @param annotations
     * @param roundEnv
     * @return
     */
    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        for (TypeElement annotation : annotations) {
            if (!"Adapt".equals(annotation.getSimpleName().toString())) {
                continue;
            }

            ExecutableElement targetAsKey = getExecutable(annotation, "value");

            for (ExecutableElement annotatedMethod: ElementFilter.methodsIn(roundEnv.getElementsAnnotatedWith(annotation))){
                if(!annotatedMethod.getModifiers().contains(Modifier.PUBLIC)){

                }
            }
        }
        return false;
    }

    private ExecutableElement getExecutable(TypeElement annotation, String methodName) {
        for (ExecutableElement method : ElementFilter.methodsIn(annotation.getEnclosedElements())) {
            if (methodName.equals(method.getSimpleName().toString())) {
                return method;
            }
        }
        processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Adapter");
        return null;
    }
}
